﻿using System;
using System.Globalization;

namespace MapDownloader.Core.Models
{
   /// <summary>
   ///    经纬度坐标
   /// </summary>
   [Serializable]
   public struct LatLngPoint
   {
      public static readonly LatLngPoint Empty = new LatLngPoint();

      /// <summary>
      ///    经度
      /// </summary>
      public double Lat { get; }

      /// <summary>
      ///    纬度
      /// </summary>
      public double Lng { get; }

      public LatLngPoint(double lat, double lng)
      {
         Lat = lat;
         Lng = lng;
      }

      /// <summary>
      ///    是否是空点
      /// </summary>
      public bool IsEmpty => Lat.Equals(0) && Lat.Equals(0);


      /// <summary>
      ///    重载
      /// </summary>
      /// <param name="obj"></param>
      /// <returns></returns>
      public override bool Equals(object obj)
      {
         if (!(obj is LatLngPoint)) return false;
         var comp = (LatLngPoint) obj;
         return comp.Lng.Equals(Lng) && comp.Lat.Equals(Lat);
      }

      /// <summary>
      ///    重载
      /// </summary>
      /// <returns></returns>
      public override int GetHashCode()
      {
         return Lng.GetHashCode() ^ Lat.GetHashCode();
      }

      /// <summary>
      ///    ToString
      /// </summary>
      /// <returns></returns>
      public override string ToString()
      {
         return string.Format(CultureInfo.CurrentCulture, "{{Lat={0}, Lng={1}}}", Lat, Lng);
      }
   }
}